<template>
  <div>
    <el-form-item :label="info.label">
      <template v-if="info.options">
        <el-select style="width: 100%;" v-model="value">
          <el-option
            v-for="(subItem, index) in info.options"
            :key="index"
            :label="subItem.label"
            :value="subItem.value"></el-option>
        </el-select>
      </template>
      <template v-else-if="info.value_type === 'list'"></template>
      <template v-else>
        <el-input></el-input>
      </template>
    </el-form-item>

    <!-- 渲染options的 -->
    <template v-if="info.options">
      <c-form-item
        v-for="(subItem, index) in getProps(info)"
        :key="index"
        :info="subItem"></c-form-item>
    </template>

    <!-- 渲染props -->
    <template v-if="info.props">
      <c-form-item
        v-for="(subItem, index) in info.props"
        :key="index"
        :info="subItem"></c-form-item>
    </template>
  </div>
</template>

<script>
export default {
  name: 'cFormItem',
  props: {
    info: Object
  },
  data() {
    return {
      value: ''
    }
  },
  methods: {
    getProps (sourceTypes) {
      const obj = sourceTypes.options.find(item => item.value === this.value)
      console.log(obj && obj.props)
      return obj && obj.props
      // return []
    }
  },
}
</script>

<style lang="scss">
</style>
